package com.huawei.esdk.tp.device.smc.convert;

import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import com.huawei.esdk.platform.common.SDKErrorCode;
import com.huawei.esdk.platform.common.SDKResult;
import com.huawei.esdk.platform.common.exception.SDKException;
import com.huawei.esdk.platform.common.utils.DateUtils;
import com.huawei.esdk.platform.common.utils.StringUtils;
import com.huawei.esdk.tp.common.ErrInfo;
import com.huawei.esdk.tp.cxf.enumgen.ConfSiteStatus;
import com.huawei.esdk.tp.cxf.enumgen.ConfSiteStatusMapping;
import com.huawei.esdk.tp.cxf.enumgen.DayOfWeekMapping;
import com.huawei.esdk.tp.cxf.enumgen.DialMode;
import com.huawei.esdk.tp.cxf.enumgen.MediaEncryptTypeMapping;
import com.huawei.esdk.tp.cxf.enumgen.PresentationTypeMapping;
import com.huawei.esdk.tp.cxf.enumgen.RecurrenceFrequency;
import com.huawei.esdk.tp.cxf.enumgen.SiteFrom;
import com.huawei.esdk.tp.cxf.enumgen.SiteType;
import com.huawei.esdk.tp.cxf.enumgen.VideoFormat;
import com.huawei.esdk.tp.cxf.enumgen.VideoProtocol;
import com.huawei.esdk.tp.domain.model.Conference;
import com.huawei.esdk.tp.domain.model.ConferenceStatus;
import com.huawei.esdk.tp.domain.model.PeriodicalConference;
import com.huawei.esdk.tp.domain.model.ScheduleConference;
import com.huawei.esdk.tp.domain.model.Site;
import com.huawei.esdk.tp.domain.model.SiteInConference;
import com.huawei.esdk.tp.domain.model.bean.ConfStatus;
import com.huawei.esdk.tp.southcommu.cxf.gen.AccessCodeSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.AddSiteInScheduledConfResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.AddSiteInScheduledConfSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ArrayOfConferenceIdSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ArrayOfDayOfWeekSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ArrayOfScheduleSiteParam2South;
import com.huawei.esdk.tp.southcommu.cxf.gen.ArrayOfStringSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ConferenceIdSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ConferenceStatusSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.DelSiteInScheduledConfResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.DelSiteInScheduledConfSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.EditFutureConfResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.EditFutureConfSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.QueryConfSitesStatusResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.QueryConfSitesStatusSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.QueryConferencesStatusResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.QueryConferencesStatusSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.RecurrenceInfoSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.RecurrenceRangeSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduleConfResponseSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduleConfSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduleSiteParam2South;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduleTimeSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduledConfInfoSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.ScheduledConfParamEx2South;
import com.huawei.esdk.tp.southcommu.cxf.gen.SiteStatusSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.TimeSpanExSouth;
import com.huawei.esdk.tp.southcommu.cxf.gen.VideoParamSouth;

/** * @author w00208247 * * */
public class TPConfMgrConvert
{
    /**
     * 南向领域bean转南向soap bean * @param srcConf /** * @param conference
     * @throws SDKException 
     */
    private void conferenceInfoCommModel2soap(ScheduleConference srcConf,
            ScheduleConfSouth dstConf) throws SDKException
    {

        ScheduledConfParamEx2South scheduledConfParamEx2South = new ScheduledConfParamEx2South();
        ConferenceIdSouth conferenceId = new ConferenceIdSouth();
        Long confId = 0l;
        if (!StringUtils.isEmpty(srcConf.getId()))
        {
            confId = Long.parseLong(srcConf.getId());
        }
        conferenceId.setConfInternalId(confId);
        scheduledConfParamEx2South.setId(conferenceId);
        scheduledConfParamEx2South.setName(srcConf.getName());
        scheduledConfParamEx2South.setAccessCode(srcConf.getAccessCode());

        ScheduleTimeSouth scheduleTimeSouth = new ScheduleTimeSouth();
        // conftime-BeginTime
        if (null != srcConf.getBeginTime())
        {
            scheduleTimeSouth.setBeginTime(DateUtils.dateToString(srcConf
                    .getBeginTime()));
        }
        TimeSpanExSouth timeSpanExSouth = new TimeSpanExSouth();
        // conftime-Duration
        timeSpanExSouth.setTimeSpan("PT" + srcConf.getLength() + "M");
        scheduleTimeSouth.setDuration(timeSpanExSouth);
        // conftime-Recurrence-周期性会议的情况，不考虑
        scheduledConfParamEx2South.setConfTime(scheduleTimeSouth);
        // 速率rate放在ScheduleConference中
        scheduledConfParamEx2South.setRate(srcConf.getRate());
        scheduledConfParamEx2South.setBillCode(srcConf.getBillCode());
        scheduledConfParamEx2South.setPassword(srcConf.getPassword());
        //cpResource是int类型，需要判断是否为null
        if (null != srcConf.getCpResouce())
        {
            scheduledConfParamEx2South.setCpResource(srcConf.getCpResouce()); 
        }
        scheduledConfParamEx2South.setMediaEncryptType(MediaEncryptTypeMapping
                .int2Enum(srcConf.getMediaEncryptType()));
        scheduledConfParamEx2South.setPresentation(PresentationTypeMapping
                .int2Enum(srcConf.getPresentation()));

        if (null != srcConf.getIsLiveBroadcast())
        {
            scheduledConfParamEx2South.setIsLiveBroadcast(0 == srcConf
                    .getIsLiveBroadcast() ? false : true);
        }
        if (null != srcConf.getIsRecording())
        {
            scheduledConfParamEx2South.setIsRecording(0 == srcConf
                    .getIsRecording() ? false : true);
        }

        dstConf.setNewConf(scheduledConfParamEx2South);

        ArrayOfScheduleSiteParam2South arrayOfScheduleSiteParam2South = new ArrayOfScheduleSiteParam2South();
        ScheduleSiteParam2South scheduleSiteParam2South = null;
        List<SiteInConference> siteInConferences = srcConf.getSites();

        // 会议中的会场数据
        for (SiteInConference siteInConference : siteInConferences)
        {
            if (null != siteInConference)
            {
                scheduleSiteParam2South = siteCommModel2soap(siteInConference);
                arrayOfScheduleSiteParam2South.getScheduleSiteParam2().add(
                        scheduleSiteParam2South);
            }
        }

        dstConf.setSites(arrayOfScheduleSiteParam2South);
    }

    /**
     * 预约会议，南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response model2soap
     * 转换对象时按照对象的粒度转换 * @param srcConf * @return
     * @throws SDKException 
     */
    public ScheduleConfSouth scheduleConfCommModel2soap(
            ScheduleConference srcConf) throws SDKException
    {
        ScheduleConfSouth dstConf = new ScheduleConfSouth();
        // 预约会议的时候给id付0
        conferenceInfoCommModel2soap(srcConf, dstConf);

        return dstConf;
    }

    /**
     * 预约周期会议，南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response model2soap
     * 转换对象时按照对象的粒度转换 * @param srcConf * @return
     * @throws SDKException 
     */
    private ScheduleConfSouth scheduleRecurrenceConfCommModel2soap(
            PeriodicalConference srcConf) throws SDKException
    {
        ScheduleConfSouth dstConf = new ScheduleConfSouth();
        // 预约会议的时候给id赋0
        conferenceInfoCommModel2soap(srcConf, dstConf);

        ScheduledConfParamEx2South scheduledConfParamEx2South = dstConf
                .getNewConf();

        ScheduleTimeSouth scheduleTimeSouth = scheduledConfParamEx2South
                .getConfTime();
        // conftime-Recurrence-周期性会议情况下的特殊情况
        RecurrenceInfoSouth recurrenceInfoSouth = new RecurrenceInfoSouth();
        if (!StringUtils.isEmpty(srcConf.getFrequency()))
        {
            recurrenceInfoSouth.setFrequency(RecurrenceFrequency
                    .valueOf(srcConf.getFrequency()));
        }
        if (null != srcConf.getInterval())
        {
            recurrenceInfoSouth.setInterval(srcConf.getInterval());
        }
        ArrayOfDayOfWeekSouth arrayOfDayOfWeekSouth = null;

        List<Integer> dayList = srcConf.getWeekDays();
        if(null != dayList && !dayList.isEmpty())
        {
            arrayOfDayOfWeekSouth = new ArrayOfDayOfWeekSouth();
            for (Integer day : dayList)
            {
                arrayOfDayOfWeekSouth.getDayOfWeek().add(
                        DayOfWeekMapping.int2Enum(day));
            }
        }
        recurrenceInfoSouth.setWeekDays(arrayOfDayOfWeekSouth);
        if (null != srcConf.getMonthDay())
        {
            recurrenceInfoSouth.setMonthDay(srcConf.getMonthDay());
        }
        if (null != srcConf.getWeekDay())
        {
            recurrenceInfoSouth.setWeekDay(srcConf.getWeekDay());
        }
        // month是月的信息，不考虑年的情况该字段不用填写
        RecurrenceRangeSouth recurrenceRangeSouth = null;
        if (null != srcConf.getCount())
        {
            recurrenceRangeSouth = new RecurrenceRangeSouth();
            recurrenceRangeSouth.setCount(srcConf.getCount());
        }
        if (null != srcConf.getEndDate() && null != recurrenceRangeSouth)
        {
            recurrenceRangeSouth.setUntilDate(DateUtils
                    .toGregorianCalendarDate(srcConf.getEndDate()));
        }
        recurrenceInfoSouth.setRange(recurrenceRangeSouth);
        scheduleTimeSouth.setRecurrence(recurrenceInfoSouth);
        // ///////////////////////周期会议特性/////////////
        dstConf.setNewConf(scheduledConfParamEx2South);

        return dstConf;
    }

    /**
     * 会场信息转换 转换时按照对象的粒度转换 南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response
     * model2soap
     * @throws SDKException 
     */
    private ScheduleSiteParam2South siteCommModel2soap(
            SiteInConference siteInConference) throws SDKException
    {
        ScheduleSiteParam2South scheduleSiteParam2South = new ScheduleSiteParam2South();
        scheduleSiteParam2South.setUri(siteInConference.getUri());
        scheduleSiteParam2South.setName(siteInConference.getName());

        if (!StringUtils.isEmpty(siteInConference.getSiteType()))
        {
            scheduleSiteParam2South.setType(SiteType.valueOf(siteInConference
                    .getSiteType()));
        }
        if (!StringUtils.isEmpty(siteInConference.getFrom()))
        {
            scheduleSiteParam2South.setFrom(SiteFrom.valueOf(siteInConference
                    .getFrom()));
        }
        if (!StringUtils.isEmpty(siteInConference.getDialingMode()))
        {
            scheduleSiteParam2South.setDialingMode(DialMode
                    .valueOf(siteInConference.getDialingMode()));
        }
        scheduleSiteParam2South.setRate(siteInConference.getRate());
        VideoParamSouth videoParamSouth = new VideoParamSouth();


        videoParamSouth.setFormat(getVideoFormatInt2Enum(siteInConference
              .getVideoFormat()));


        videoParamSouth.setProtocol(getVideoProtocolInt2Enum(siteInConference
              .getVideoProtocol()));

        // TE30会场，当video节点没有值的时候  需要删除video节点，否则无法呼入会场
        if(null == siteInConference.getVideoFormat()&& null == siteInConference.getVideoProtocol())
        {
            scheduleSiteParam2South.setVideo(null);
        }
        else
        {
            scheduleSiteParam2South.setVideo(videoParamSouth);
        }

        return scheduleSiteParam2South;
    }

    /**
     * 预约会议 南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    private void setConferenceEx(ScheduleConfResponseSouth resMsg,
            ScheduleConference desMsg)
    {
        ScheduledConfInfoSouth scheduledConfInfoSouth = resMsg.getConfs()
                .getScheduledConfInfo().get(0);
        desMsg.setId(scheduledConfInfoSouth.getId().getConfInternalId()
                .toString());
        List<AccessCodeSouth> arrayOfAccessCodeSouth = scheduledConfInfoSouth
                .getAccessCode().getAccessCode();
        List<SiteInConference> siteInConferences = new ArrayList<SiteInConference>();
        SiteInConference siteInConference = null;
        for (AccessCodeSouth accessCodeSouth : arrayOfAccessCodeSouth)
        {
            siteInConference = siteCommSoap2model(accessCodeSouth);
            siteInConferences.add(siteInConference);
        }
        desMsg.setSites(siteInConferences);
        
        //Add in R3
        desMsg.setRecorderAddr(scheduledConfInfoSouth.getRecorderAddr());

    }

    /**
     * 预约会议 南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    private SDKResult<ScheduleConference> scheduleConfCommSoap2model(
            ScheduleConfResponseSouth resMsg)
    {

        SDKResult<ScheduleConference> result = new SDKResult<ScheduleConference>();
        long errorCode = resMsg.getScheduleConfResult().getErrCode();
        result.setErrCode(resMsg.getScheduleConfResult().getErrCode());

        if (0 != errorCode)
        {
            return result;
        }
        ScheduleConference desMsg = new ScheduleConference();

        setConferenceEx(resMsg, desMsg);
        result.setResult(desMsg);

        return result;
    }

    /**
     * 预约周期会议会议 南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    private SDKResult<PeriodicalConference> scheduleRecurrenceConfCommSoap2model(
            ScheduleConfResponseSouth resMsg)
    {

        SDKResult<PeriodicalConference> result = new SDKResult<PeriodicalConference>();
        long errorCode = resMsg.getScheduleConfResult().getErrCode();
        result.setErrCode(resMsg.getScheduleConfResult().getErrCode());

        if (0 != errorCode)
        {
            return result;
        }
        PeriodicalConference desMsg = new PeriodicalConference();

        setConferenceEx(resMsg, desMsg);
        result.setResult(desMsg);

        return result;
    }

    /**
     * 预约会议中会场信息的转换 南向soapbean转南向领域bean 用于返回值的情况 ModelBean
     * soap2model(SoapBean){}
     */
    private SiteInConference siteCommSoap2model(AccessCodeSouth accessCodeSouth)
    {

        SiteInConference siteInConference = new SiteInConference();
        siteInConference.setUri(accessCodeSouth.getSiteUri());
        siteInConference.setName(accessCodeSouth.getSiteName());
        siteInConference.setAccessCode(accessCodeSouth.getConfAccessCode());
        siteInConference.setBeginTime(DateUtils.toDate(accessCodeSouth
                .getBeginTime()));

        return siteInConference;
    }

    /**
     * 预约会议,scheduleConf 南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response model2soap
     * @throws SDKException 
     */
    public ScheduleConfSouth scheduleConfModel2soap(ScheduleConference srcConf) throws SDKException
    {
        return scheduleConfCommModel2soap(srcConf);
    }

    /**
     * 预约会议，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public SDKResult<ScheduleConference> scheduleConfSoap2model(
            ScheduleConfResponseSouth resMsg)
    {
        return scheduleConfCommSoap2model(resMsg);
    }

    /**
     * 预约会议,scheduleConf 南向领域bean转南向soap bean 用于向SMC产品发消息的情况 response model2soap
     * @throws SDKException 
     */
    public ScheduleConfSouth scheduleRecurrenceConfModel2soap(
            PeriodicalConference srcConf) throws SDKException
    {
        return scheduleRecurrenceConfCommModel2soap(srcConf);
    }

    /**
     * 预约会议，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public SDKResult<PeriodicalConference> scheduleRecurrenceConfSoap2model(
            ScheduleConfResponseSouth resMsg)
    {
        return scheduleRecurrenceConfCommSoap2model(resMsg);
    }

    /**
     * 修改会议的bean的convert方法和预约会议的类似 修改会议，南向领域bean转南向soap bean 用于向SMC产品发消息的情况
     * response model2soap
     * @throws SDKException 
     */
    public EditFutureConfSouth editScheduleConfModel2soap(
            ScheduleConference srcConf) throws SDKException
    {
        ScheduleConfSouth scheduleConfSouth = scheduleConfCommModel2soap(srcConf);

        EditFutureConfSouth editFutureConfSouth = new EditFutureConfSouth();
        editFutureConfSouth.setEditConf(scheduleConfSouth.getNewConf());
        editFutureConfSouth.setSites(scheduleConfSouth.getSites());

        return editFutureConfSouth;
    }

    /**
     * 预约会议，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public SDKResult<ScheduleConference> editScheduleConfSoap2model(
            EditFutureConfResponseSouth resMsg)
    {

        ScheduleConfResponseSouth scheduleConfResponseSouth = new ScheduleConfResponseSouth();
        scheduleConfResponseSouth.setConfs(resMsg.getConfs());
        scheduleConfResponseSouth.setScheduleConfResult(resMsg
                .getEditFutureConfResult());

        return scheduleConfSoap2model(scheduleConfResponseSouth);
    }

    /**
     * 修改周期会议的bean的convert方法和预约会议的类似 修改会议，南向领域bean转南向soap bean 用于向SMC产品发消息的情况
     * response model2soap
     * @throws SDKException 
     */
    public EditFutureConfSouth editSchedulePeriodicalConfModel2soap(
            PeriodicalConference srcConf) throws SDKException
    {
        ScheduleConfSouth scheduleConfSouth = scheduleConfCommModel2soap(srcConf);

        // conftime-Recurrence-周期性会议情况下的特殊情况
        if(null != srcConf.getInterval() &&
            !StringUtils.isEmpty(srcConf.getFrequency()))
        {
            RecurrenceInfoSouth recurrenceInfoSouth = new RecurrenceInfoSouth();

            recurrenceInfoSouth.setFrequency(RecurrenceFrequency
                    .valueOf(srcConf.getFrequency()));

            recurrenceInfoSouth.setInterval(srcConf.getInterval());
            
            ArrayOfDayOfWeekSouth arrayOfDayOfWeekSouth = null;
    
            List<Integer> dayList = srcConf.getWeekDays();
            if(null != dayList && !dayList.isEmpty())
            {
                arrayOfDayOfWeekSouth = new ArrayOfDayOfWeekSouth();
                for (Integer day : dayList)
                {
                    arrayOfDayOfWeekSouth.getDayOfWeek().add(
                            DayOfWeekMapping.int2Enum(day));
                }
            }
            recurrenceInfoSouth.setWeekDays(arrayOfDayOfWeekSouth);
            if (null != srcConf.getMonthDay())
            {
                recurrenceInfoSouth.setMonthDay(srcConf.getMonthDay());
            }
            if (null != srcConf.getWeekDay())
            {
                recurrenceInfoSouth.setWeekDay(srcConf.getWeekDay());
            }
            // month是月的信息，不考虑年的情况该字段不用填写
            RecurrenceRangeSouth recurrenceRangeSouth = null;
            if (null != srcConf.getCount())
            {
                recurrenceRangeSouth = new RecurrenceRangeSouth();
                recurrenceRangeSouth.setCount(srcConf.getCount());
            }
            if (null != srcConf.getEndDate() && null != recurrenceRangeSouth)
            {
                recurrenceRangeSouth.setUntilDate(DateUtils
                        .toGregorianCalendarDate(srcConf.getEndDate()));
            }
            recurrenceInfoSouth.setRange(recurrenceRangeSouth);
            scheduleConfSouth.getNewConf().getConfTime()
                    .setRecurrence(recurrenceInfoSouth);
        }

        EditFutureConfSouth editFutureConfSouth = new EditFutureConfSouth();
        editFutureConfSouth.setEditConf(scheduleConfSouth.getNewConf());
        editFutureConfSouth.setSites(scheduleConfSouth.getSites());
        //C30修改
        if(null != srcConf.getSubConfStartTime())
        {
            editFutureConfSouth.setBeginTime(DateUtils
                        .toGregorianCalendarDate(srcConf.getSubConfStartTime()));
        }
        return editFutureConfSouth;
    }

    /**
     * 修改周期会议，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public SDKResult<PeriodicalConference> editScheduleRecurrenceConfSoap2model(
            EditFutureConfResponseSouth resMsg)
    {

        ScheduleConfResponseSouth scheduleConfResponseSouth = new ScheduleConfResponseSouth();
        scheduleConfResponseSouth.setConfs(resMsg.getConfs());
        scheduleConfResponseSouth.setScheduleConfResult(resMsg
                .getEditFutureConfResult());

        return scheduleRecurrenceConfSoap2model(scheduleConfResponseSouth);
    }

    /**
     * 查询会议会场状态，南向soapbean转南向领域bean 用于返回值的情况 ModelBean soap2model(SoapBean){}
     */
    public SDKResult<List<SiteInConference>> queryConfSiteStatusSoap2model(
            QueryConfSitesStatusResponseSouth res)
    {

        SDKResult<List<SiteInConference>> result = new SDKResult<List<SiteInConference>>();

        int resultCode = -1;
        // 南向发送soap消息，产品返回soap消息
        resultCode = (int) res.getQueryConfSitesStatusResult().getErrCode();
        // 南向发送soap消息，产品返回soap消息
        if (resultCode == 0)
        {
            SiteInConference confSiteStatusMap = null;
            List<SiteInConference> sites = new ArrayList<SiteInConference>();
            List<SiteStatusSouth> southArrayOfSiteStatus = res.getSitesStatus()
                    .getSiteStatus();
            // 会场列表，可以有多个会场（当一个会场添加了N次的时候，该会场会显示1次）
            for (int j = 0; j < southArrayOfSiteStatus.size(); j++)
            {
                confSiteStatusMap = new SiteInConference();
                confSiteStatusMap
                        .setUri(southArrayOfSiteStatus.get(j).getUri());

                ConfSiteStatus sonfSiteStatusSouth = southArrayOfSiteStatus
                        .get(j).getStatus();
                confSiteStatusMap.setStatus(ConfSiteStatusMapping
                        .enum2Int(sonfSiteStatusSouth));
                // 行业接口对外开放的ConfSiteStatus类型中，不包含Noexist,如果SMC返回的是Noexist的情况，视为Unknow
                confSiteStatusMap.setName(southArrayOfSiteStatus.get(j)
                        .getName());
                confSiteStatusMap.setSiteType(southArrayOfSiteStatus.get(j)
                        .getType().toString());
                confSiteStatusMap.setVideoSource(southArrayOfSiteStatus.get(j)
                        .getVideoSource());
                confSiteStatusMap.setVolume(southArrayOfSiteStatus.get(j)
                        .getVolume());
                if (southArrayOfSiteStatus.get(j).isIsQuiet())
                {
                    confSiteStatusMap.setIsQuiet(1);
                }
                else
                {
                    confSiteStatusMap.setIsQuiet(0);
                }
                if (southArrayOfSiteStatus.get(j).isIsMute())
                {
                    confSiteStatusMap.setIsMute(1);
                }
                else
                {
                    confSiteStatusMap.setIsMute(0);
                }

                sites.add(confSiteStatusMap);
            }
            result.setResult(sites);
        }
        result.setErrCode(res.getQueryConfSitesStatusResult().getErrCode());

        return result;
    }

    /**
     * 查询会议状态，领域bean转南向bean * @param confIds /** * @return
     */
    public QueryConferencesStatusSouth list2QueryConferencesStatusSouth(
            List<String> confIds)
    {
        QueryConferencesStatusSouth queryConferencesStatusSouth = new QueryConferencesStatusSouth();
        ArrayOfConferenceIdSouth arrayOfConferenceIdSouth = new ArrayOfConferenceIdSouth();
        ConferenceIdSouth conferenceId = null;
        for (int i = 0; i < confIds.size(); i++)
        {
            conferenceId = new ConferenceIdSouth();
            conferenceId.setConfInternalId(Long.parseLong(confIds.get(i)));
            arrayOfConferenceIdSouth.getConferenceId().add(conferenceId);
        }

        queryConferencesStatusSouth.setConfIds(arrayOfConferenceIdSouth);
        return queryConferencesStatusSouth;
    }

    public SDKResult<List<Conference>> queryConferencesStatusResponseSouth2SDKResult(
            QueryConferencesStatusResponseSouth response)
    {
        SDKResult<List<Conference>> result = new SDKResult<List<Conference>>();
        result.setErrCode(response.getQueryConferencesStatusResult()
                .getErrCode());
        result.setDescription(response.getQueryConferencesStatusResult()
                .getDescription());
        result.setSubSystem(String.valueOf(response
                .getQueryConferencesStatusResult().getSubSystem()));

        List<Conference> list = new LinkedList<Conference>();
        Conference conf = null;
        if (null != response.getConfsStatus()
                && response.getConfsStatus().getConferenceStatus().size() > 0)
        {
            for (int i = 0; i < response.getConfsStatus().getConferenceStatus()
                    .size(); i++)
            {
                ConferenceStatusSouth conferenceStatus = response
                        .getConfsStatus().getConferenceStatus().get(i);
                conf = new Conference(conferenceStatus.getId()
                        .getConfInternalId().toString());
                conf.setName(conferenceStatus.getName());
                conf.setStatus(ConfStatus.valueOf(conferenceStatus.getStatus()
                        .toString()));
                ConferenceStatus confStatus = new ConferenceStatus();
                confStatus.setBroadcast(conferenceStatus.getBroadcast());
                confStatus.setChair(conferenceStatus.getChair());
                confStatus.setId(conferenceStatus.getId().getConfInternalId()
                        .toString());
                confStatus.setName(conferenceStatus.getName());
                confStatus.setSpeaking(conferenceStatus.getSpeaking());
                confStatus.setStatus(conferenceStatus.getStatus().toString());
                conf.setConferenceStatus(confStatus);
                list.add(conf);
            }
        }

        result.setResult(list);
        return result;
    }

    public AddSiteInScheduledConfSouth addSiteToScheduledConfModel2SouthSoap(
            ScheduleConference conference, Site site, Date beginTime,
            boolean useAnonymousSite) throws SDKException
    {
        // 领域Bean转成南向SOAP Bean
        AddSiteInScheduledConfSouth southRequest = new AddSiteInScheduledConfSouth();
        ConferenceIdSouth conferenceId = new ConferenceIdSouth();
        ScheduleSiteParam2South siteParam = new ScheduleSiteParam2South();

        conferenceId.setConfInternalId(Long.parseLong(conference.getId()));
        southRequest.setConfId(conferenceId);

        siteParam.setName(site.getName());
        if (!StringUtils.isEmpty(site.getSiteType()))
        {
            siteParam.setType(SiteType.valueOf(site.getSiteType()));
        }
        siteParam
                .setDialingMode(StringUtils.isEmpty(site.getDialingMode()) ? null
                        : DialMode.valueOf(site.getDialingMode()));
        siteParam.setUri(site.getUri());
        siteParam.setRate(site.getRate());
        siteParam.setFrom(StringUtils.isEmpty(site.getFrom()) ? null : SiteFrom
                .valueOf(site.getFrom()));
        VideoParamSouth videoParamSouth = new VideoParamSouth();
        videoParamSouth
                .setFormat(getVideoFormatInt2Enum(site.getVideoFormat()));
        videoParamSouth
                .setProtocol(getVideoProtocolInt2Enum(site.getVideoProtocol()));
        siteParam.setVideo(videoParamSouth);

        southRequest.setSiteParam(siteParam);
        southRequest.setBeginTime(DateUtils.toGregorianCalendarDate(beginTime));
        southRequest.setIsUseAnonymousSite(useAnonymousSite);

        return southRequest;
    }

    public SDKResult<ScheduleConference> addSiteToScheduledConfSouthSoap2Model(
            ScheduleConference conference, Site site,
            AddSiteInScheduledConfResponseSouth southResponse)
    {
        // 将SMC返回的南向SOAP Bean转成领域Bean
        SDKResult<ScheduleConference> modelBean = new SDKResult<ScheduleConference>();

        if (null == southResponse)
        {
            modelBean.setErrCode(ErrInfo.SDK_SYSTEM_ERRORCODE);
            return modelBean;
        }

        // 1.设置错误码
        modelBean.setErrCode(southResponse.getAddSiteInScheduledConfResult()
                .getErrCode());

        // 2.将南向SMC SOAP
        // Bean中的AccessCode对象属性设置到领域模型Conference终的SiteInConference中
        if (null != southResponse.getConfs())
        {
            List<AccessCodeSouth> accessCodeSouths = new ArrayList<AccessCodeSouth>();
            for (int i = 0; i < southResponse.getConfs().getScheduledConfInfo()
                    .size(); i++)
            {
                accessCodeSouths.addAll(southResponse.getConfs()
                        .getScheduledConfInfo().get(i).getAccessCode()
                        .getAccessCode());
            }

            List<SiteInConference> siteInConferences = new ArrayList<SiteInConference>();
            AccessCodeSouth accessCodeSouth = null;
            SiteInConference siteInConference = null;
            for (int i = 0; i < accessCodeSouths.size(); i++)
            {
                accessCodeSouth = accessCodeSouths.get(i);
                siteInConference = new SiteInConference(conference.getId(),
                        site.getUri());

                siteInConference.setConfAccessCode(accessCodeSouth
                        .getConfAccessCode());
                siteInConference.setName(accessCodeSouth.getSiteName());
                siteInConference.setUri(accessCodeSouth.getSiteUri());
                siteInConference.setBeginTime(accessCodeSouth.getBeginTime()
                        .toGregorianCalendar().getTime());
                siteInConference.setMcuUri(accessCodeSouth.getMcuUri());

                siteInConferences.add(siteInConference);
            }
            conference.setSites(siteInConferences);
            modelBean.setResult(conference);
        }
        

        return modelBean;
    }

    public DelSiteInScheduledConfSouth delSiteFromScheduledConfModel2Soap(
            String confId, String siteUri)
    {
        DelSiteInScheduledConfSouth southRequest = new DelSiteInScheduledConfSouth();
        ConferenceIdSouth conferenceIdSouth = new ConferenceIdSouth();

        conferenceIdSouth.setConfInternalId(Long.parseLong(confId));
        southRequest.setConfId(conferenceIdSouth);
        southRequest.setSiteUri(siteUri);

        return southRequest;
    }

    // delSiteFromScheduledConfModel2Soap需要统一成南向的
    public DelSiteInScheduledConfSouth delSiteFromScheduledConfModel2Soap(
            String confId, SiteInConference site)
    {
        DelSiteInScheduledConfSouth southRequest = new DelSiteInScheduledConfSouth();
        ConferenceIdSouth conferenceIdSouth = new ConferenceIdSouth();

        conferenceIdSouth.setConfInternalId(Long.parseLong(confId));
        southRequest.setConfId(conferenceIdSouth);
        southRequest.setSiteUri(site.getUri());
        southRequest.setBeginTime(DateUtils.toGregorianCalendarDate(site.getBeginTime()));

        return southRequest;
    }

    public SDKErrorCode delSiteFromScheduledConfSoap2Model(
            DelSiteInScheduledConfResponseSouth southResponse)
    {
        SDKErrorCode errorCode = new SDKErrorCode();
        errorCode.setErrCode(southResponse.getDelSiteInScheduledConfResult()
                .getErrCode());

        return errorCode;
    }

    public QueryConfSitesStatusSouth queryConfSitesStatusModel2Soap(
            String confId, List<String> siteUris)
    {
        // 定义协议相关的Bean
        QueryConfSitesStatusSouth reqBean = new QueryConfSitesStatusSouth();

        // 会议ID
        ConferenceIdSouth conferenceId = new ConferenceIdSouth();

        conferenceId.setConfInternalId(Long.parseLong(confId));
        reqBean.setConfId(conferenceId);

        ArrayOfStringSouth arrayOfString = new ArrayOfStringSouth();
        /*
         * DTS单号: DTS2013042605527 会场uri为空 查询出所有
         */
        if (null == siteUris)
        {
            reqBean.setSiteUris(arrayOfString);
            return reqBean;
        }

        if (1 == siteUris.size())
        {
            if ("".equals(siteUris.get(0)))
            {
                reqBean.setSiteUris(arrayOfString);
            }
            else
            {
                arrayOfString.getString().add(siteUris.get(0));
                reqBean.setSiteUris(arrayOfString);
            }
        }
        else
        {
            for (int i = 0; i < siteUris.size(); i++)
            {
                arrayOfString.getString().add(siteUris.get(i));
            }
            reqBean.setSiteUris(arrayOfString);
        }
        return reqBean;
    }
    
    private VideoFormat getVideoFormatInt2Enum(Integer num) 
        throws SDKException
    {
        final int CIF_4 = 0;
        final int P_720 = 1;
        final int P_1080 = 2;
        final int P_480 = 3;
        final int P_720_60_F = 4;
        final int P_1080_60_F = 5;
        final int MIN = 0;
        final int MAX = 5;

        if(null==num){
            return null;
        }
        
        if(num < MIN || num > MAX)
        {
            SDKException sdkException = new SDKException(ErrInfo.DATA_ERRORDESC);
            sdkException.setSdkErrCode(ErrInfo.DATA_ERRORCODE);
            throw sdkException;
        }
        
        switch (num) {
            case CIF_4: {
                return VideoFormat.CIF_4;
            }
            case P_720: {
                return VideoFormat.P_720;
            }
            case P_1080: {
                return VideoFormat.P_1080;
            }
            case P_480: {
                return VideoFormat.P_480;
            }
            case P_720_60_F: {
                return VideoFormat.P_720_60_F;
            }
            case P_1080_60_F: {
                return VideoFormat.P_1080_60_F;
            }
            default: {
                return null;
            }
        }
    }
    
    private VideoProtocol getVideoProtocolInt2Enum(Integer num) 
        throws SDKException
    {
        final int H_261 = 0;
        final int H_263 = 1;
        final int H_264 = 2;
        final int MIN = 0;
        final int MAX = 2;

        if(null==num){
            return null;
        }
        
        if(num < MIN || num > MAX)
        {
            SDKException sdkException = new SDKException(ErrInfo.DATA_ERRORDESC);
            sdkException.setSdkErrCode(ErrInfo.DATA_ERRORCODE);
            throw sdkException;
        }
        
        switch (num) 
        {
            case H_261: {
                return VideoProtocol.H_261;
            }
            case H_263: {
                return VideoProtocol.H_263;
            }
            case H_264: {
                return VideoProtocol.H_264;
            }
            default: {
                return null;
            }
        }
    }
}
